home *** CD-ROM | disk | FTP | other *** search
/ Scene 96 / Scene 96 International Edition (Zyklop Software) (Disc 2) (1997).iso / misc / coding / ct_xmp15 / cppexam.cpp < prev    next >
C/C++ Source or Header  |  1996-09-15  |  2KB  |  113 lines

  1. #include <string.h>
  2. #include <ctype.h>
  3. #include <process.h>
  4. #include <conio.h>
  5. #include <io.h>
  6. #include <fcntl.h>
  7. #include <stdlib.h>
  8. #include "mxmplay.h"
  9.  
  10. void setcurshape(unsigned short);
  11. #pragma aux setcurshape parm [cx] modify [ax] = "mov ax,0103h" "int 10h"
  12.  
  13. void main()
  14. {
  15.   cputs("mxm player example    (c) '95/96 Niklas Beisert / pascal\r\n\n");
  16.  
  17.   char cmdline[128];
  18.   char *cmdp=cmdline;
  19.   getcmd(cmdline);
  20.   while (isspace(*cmdp))
  21.     cmdp++;
  22.  
  23.   char *cmdpe=cmdp;
  24.   while (*cmdpe&&!isspace(*cmdpe))
  25.     cmdpe++;
  26.   cmdpe=0;
  27.  
  28.   if (!*cmdp)
  29.   {
  30.     cputs("argument error\r\n");
  31.     return;
  32.   }
  33.  
  34.   char fname[_MAX_FNAME];
  35.   char path[_MAX_PATH];
  36.   char drive[_MAX_DRIVE];
  37.   char dir[_MAX_DIR];
  38.   _splitpath(cmdp, drive, dir, fname, 0);
  39.   _makepath(path, drive, dir, fname, ".mxm");
  40.  
  41.   int f=open(path, O_RDONLY|O_BINARY);
  42.   if (f<0)
  43.   {
  44.     cputs("file error\r\n");
  45.     return;
  46.   }
  47.   unsigned char *mxmmem=new unsigned char [filelength(f)+0x4000];
  48.   if (!mxmmem)
  49.   {
  50.     cputs("malloc error\r\n");
  51.     return;
  52.   }
  53.   cputs("loading file...");
  54.  
  55.   read(f, mxmmem+0x4000, filelength(f));
  56.   close(f);
  57.  
  58.   cputs("\r\nuploading samples...");
  59.   if (!xmpInit(mxmmem+0x4000, xmpGetGUSPort(xmpGetEnvPtrDPMI(_psp)), mxmmem, 65536, MXMINTMODEDOS))
  60.   {
  61.     cputs("player error\r\n");
  62.     return;
  63.   }
  64.  
  65.   cputs("\r\nplaying module...\r\n");
  66.   xmpPlay(0);
  67.   setcurshape(0x2000);
  68.  
  69.   while (!kbhit())
  70.   {
  71.     unsigned short pos=xmpGetPos();
  72.     unsigned long tim=xmpGetTimer()/1193046;
  73.     unsigned char sync=xmpGetSync();
  74.     char str[20];
  75.     str[0]=13;
  76.     str[1]="0123456789ABCDEF"[(tim>>12)&0xF];
  77.     str[2]="0123456789ABCDEF"[(tim>>8)&0xF];
  78.     str[3]="0123456789ABCDEF"[(tim>>4)&0xF];
  79.     str[4]="0123456789ABCDEF"[(tim>>0)&0xF];
  80.     str[5]=' ';
  81.     str[6]="0123456789ABCDEF"[(pos>>12)&0xF];
  82.     str[7]="0123456789ABCDEF"[(pos>>8)&0xF];
  83.     str[8]=' ';
  84.     str[9]="0123456789ABCDEF"[(pos>>4)&0xF];
  85.     str[10]="0123456789ABCDEF"[(pos>>0)&0xF];
  86.     str[11]=' ';
  87.     str[12]="0123456789ABCDEF"[(sync>>4)&0xF];
  88.     str[13]="0123456789ABCDEF"[(sync>>0)&0xF];
  89.     str[14]=0;
  90.     cputs(str);
  91.   }
  92.   setcurshape(0xD0E);
  93.  
  94.   cputs("\r\n");
  95.  
  96.   unsigned long t0=xmpGetTimer();
  97.   while (1)
  98.   {
  99.     signed long t1=(xmpGetTimer()-t0);
  100.     if (t1>596523)
  101.       break;
  102.     if (t1>0)
  103.       xmpSetVolume(64-t1/9321);
  104.   }
  105.  
  106.   xmpStop();
  107.  
  108.   delete mxmmem;
  109.  
  110.   while (kbhit())
  111.     getch();
  112. }
  113.